package com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.common.utils.ZhjdIotUtils;
import com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.entity.AsphaltLowTemperatureElongationEntity;
import com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.entity.AsphaltLowTemperatureElongationResEntity;
import com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.entity.CJLiQingYanDu;
import com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.service.AsphaltLowTemperatureElongationResService;
import com.qzsoft.zhjd.laboratory.modules.asphaltLowTemperatureElongation.service.AsphaltLowTemperatureElongationService;
import com.qzsoft.zhjd.laboratory.modules.asphaltSofteningPoint.entity.AsphaltSofteningPointResEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 沥青低温延伸度试验仪
 *
 * @author sx
 * @email 
 * @date 2023-07-11 16:37:53
 */
@RestController
@RequestMapping("laboratory/asphaltLowTemperatureElongation")
public class AsphaltLowTemperatureElongationController {

    @Autowired
    private AsphaltLowTemperatureElongationService asphaltLowTemperatureElongationService;

    @Autowired
    private AsphaltLowTemperatureElongationResService asphaltLowTemperatureElongationResService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:page")
    public Result page(@RequestParam Map<String, Object> params){
        IPage page = asphaltLowTemperatureElongationService.queryPage(params);
        return ResultUtils.ok(page);
    }

    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:find")
    public Result find(@PathVariable("id") String id){
		AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation = asphaltLowTemperatureElongationService.getInfo(id);
        return ResultUtils.ok(asphaltLowTemperatureElongation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:save")
    public Result save(@RequestBody AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation){
		asphaltLowTemperatureElongationService.saveData(asphaltLowTemperatureElongation);
        return ResultUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:update")
    public Result update(@RequestBody AsphaltLowTemperatureElongationEntity asphaltLowTemperatureElongation){
        asphaltLowTemperatureElongationService.updateData(asphaltLowTemperatureElongation);
        return ResultUtils.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:delete")
    public Result deleteOne(@PathVariable("id") String id){
        asphaltLowTemperatureElongationService.deleteOneData(id);
        return ResultUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("laboratory:asphaltLowTemperatureElongation:delete")
    public Result delete(@RequestBody String[] ids){
        asphaltLowTemperatureElongationService.deleteData(Arrays.asList(ids));
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public Result parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltLowTemperatureElongationService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

    /**
     * 解析上海昌吉数据

     * @return
     */
    @PostMapping("/parsingCJData")
    public Result parsingCJData(@RequestBody CJLiQingYanDu cjLiQingYanDu){
        asphaltLowTemperatureElongationResService.saveCJData(cjLiQingYanDu);
        return ResultUtils.ok(cjLiQingYanDu.getId());
    }


    /**
     * 重新解析航天科宇沥青延度数据v2.X
     * @param deviceId
     * @return
     */
    @PostMapping("/reParsingData/{deviceId}")
    public Result reParsingData(@PathVariable("deviceId") String deviceId){
        asphaltLowTemperatureElongationService.reParsingData(deviceId);
        return ResultUtils.ok();
    }


    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    @RequiresPermissions("laboratory:asphaltSofteningPointRes:changeSample")
    public Result changeSample(@RequestBody AsphaltLowTemperatureElongationResEntity asphaltLowTemperatureElongationRes){
        asphaltLowTemperatureElongationService.changeSample(asphaltLowTemperatureElongationRes);
        return ResultUtils.ok();
    }

    /**
     * 低温延度仪 -- 北京中科建仪电子科技有限公司
     */
    @PostMapping("/parsingDataBjzkjydz/{deviceId}")
    public Result parsingDataBjzkjydz(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltLowTemperatureElongationService.parsingDataBjzkjydz(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

    /**
     * 云检科技 - 低温延度仪
     */
    @PostMapping("/parsingDataYjkj/{deviceId}")
    public Result parsingDataYjkj(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltLowTemperatureElongationService.parsingDataYjkj(ZhjdIotUtils.dataParsing(req),deviceId);
        return ResultUtils.ok();
    }

}
